<template>
  <div class="outer">
    <div class="pay_content middle">
      <h2>我的账户</h2>
      <div class="my_money">
        <span>余额：</span>
        <span class="money-num">{{ myMessage[0].wallet }} 元</span>
        <span class="tag" v-show="myMessage[0].wallet == 100"
          >首次注册100元体验金</span
        >
      </div>
      <div class="recharge">
        <el-form
          :label-position="labelPosition"
          label-width="130px"
          :model="formLabelAlign"
        >
          <el-form-item label="请输入充值金额：">
            <el-input-number
              :min="0"
              v-model.number="formLabelAlign.money"
            ></el-input-number>
          </el-form-item>
        </el-form>
      </div>
      <el-button @click="pay_btn" type="danger" :plian="true"
        >确定支付</el-button
      >
    </div>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
  "homePage"
);
export default {
  data() {
    return {
      tableData: [{ name: "保险", price: "100" }],
      labelPosition: "left",
      formLabelAlign: {
        money: "",
      },
    };
  },
  created() {
    this.getMessage(localStorage._id);
  },
  computed: {
    ...mapState(["myMessage"]),
  },
  methods: {
    ...mapActions(["getMessage", "updateWallet"]),
    async pay_btn() {
      const data = await this.updateWallet({
        money: this.formLabelAlign.money,
        _id: localStorage._id,
      });
      if (data.status) {
        this.$message({
          message: "恭喜你，充值成功！",
          type: "success",
        });
        this.getMessage(localStorage._id);
      } else {
        this.$message.error("对不起，充值失败！");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.outer {
  width: 100%;
  .pay_content {
    width: 100%;

    h1 {
      font-size: 25px;
      color: rgb(42, 84, 209);
    }
    h2 {
      font-size: 16px;
    }
    .my_money {
      font-size: 20px;
      .money-num {
        font-size: 16px;
        color: red;
      }
      .tag {
        margin-left: 15px;
        font-size: 13px;
        color: #9e9e9e;
      }
    }
    .el-button {
      margin-top: 20px;
      &:hover {
        translate: 1s;
        background-color: rgb(42, 84, 209);
        color: white;
        border: 1px solid rgb(42, 84, 209);
      }
    }
    .recharge {
      width: 300px;
      margin-top: 20px;
    }
  }
}
</style>